/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.ds;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SrcDataset implements Serializable
{
	
	/* used only by web interace */
	boolean subscribed;
	public boolean isSubscribed()
	{
		return subscribed;
	}
	public void setSubscribed(boolean subscribed)
	{
		this.subscribed = subscribed;
	}

	String compression;
	String baseurl;
	String displayName;
	String filename;
	String format;
	long id;
	String name;
	boolean enabled;
	String type;
	boolean indexable;
	boolean staticUrl;
	
	List<Version> versions=new ArrayList<Version>();
	List<Patch> patches=new ArrayList<Patch>();
	
	public List<Version> getVersions()
	{
		return versions;
	}
	public List<Patch> getPatches()
	{
		return patches;
	}
	public String getCompression()
	{
		return compression;
	}
	public void setCompression(String compression)
	{
		this.compression = compression;
	}
	public String getBaseurl()
	{
		return baseurl;
	}
	public void setBaseurl(String baseurl)
	{
		this.baseurl = baseurl;
	}
	public String getDisplayName()
	{
		return displayName;
	}
	public void setDisplayName(String displayName)
	{
		this.displayName = displayName;
	}
	public String getFilename()
	{
		return filename;
	}
	public void setFilename(String filename)
	{
		this.filename = filename;
	}
	public String getFormat()
	{
		return format;
	}
	public void setFormat(String format)
	{
		this.format = format;
	}
	public long getId()
	{
		return id;
	}
	public void setId(long id)
	{
		this.id = id;
	}
	public String getName()
	{
		return name;
	}
	public void setName(String name)
	{
		this.name = name;
	}
	public boolean isEnabled()
	{
		return enabled;
	}
	public void setEnabled(boolean enabled)
	{
		this.enabled = enabled;
	}
	public String getType()
	{
		return type;
	}
	public void setType(String type)
	{
		this.type = type;
	}
	public boolean isIndexable()
	{
		return indexable;
	}
	public void setIndexable(boolean indexable)
	{
		this.indexable = indexable;
	}
	public boolean isStaticUrl()
	{
		return staticUrl;
	}
	public void setStaticUrl(boolean staticUrl)
	{
		this.staticUrl = staticUrl;
	}
	public boolean isProtein() 
	{
		return getType().equals("P")?true:false;
	}
	public boolean isDNA()
	{
		return getType().equals("N")?true:false;
	}
	public boolean isGzip() 
	{
		return compression!=null && compression.equals("gzip");
	}
	
	public Version getMostRecentVersion()
	{
		if (versions.isEmpty())
			return null;
		Collections.sort(versions, new Comparator<Version>(){

			public int compare(Version o1, Version o2)
			{
				return -(o1.version.compareTo(o2.version));
			}});
		return versions.get(0);
	}
	
	public Version getVersion(String v)
	{
		if (versions.isEmpty())
			return null;
		for (Version ver:versions)
		{
			if (ver.getVersion().equals(ver))
			{
				return ver;
			}
		}
		return null;
	}
	
	public Patch getPatchByPerversion(String perver)
	{
		for (Patch p:patches)
		{
			if (p.getPreversion().equals(perver))
			{
				return p;
			}
		}
		return null;
	}
	
	
}
